//
//  OpenGLESView.m
//  TestGameEngine
//
//  Created by Louis CHU on 21/03/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "OpenGLESView.h"
#import "UpdaterManager.h"
#import "RenderManager.h"
#import "IGraphicRenderer.h"
#import "OpenGLES1Renderer.h"
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/EAGLDrawable.h>

@interface OpenGLESView ()
@end
@implementation OpenGLESView
//@synthesize renderer;

+ (Class) layerClass
{
    return [CAEAGLLayer class];
}

- (id) initWithCoder:(NSCoder*)coder
{    
    if ((self = [super initWithCoder:coder]))
	{
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
        
        eaglLayer.opaque = TRUE;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
        
        
        
        [[UpdaterManager sharedUpdaterManager] addUpdatedObject:self];
    }
	
    return self;
}

- (void) layoutSubviews
{
	[super layoutSubviews];
    [[RenderManager sharedRenderManager].graphicRenderer resizeFromLayer:(CAEAGLLayer*)self.layer];
    [[RenderManager sharedRenderManager] render];
}

- (void) update: (float) elapsedTime
{
    [[RenderManager sharedRenderManager] render];
}


@end
